/*
 * This file is part of the quickTools support library, dubbed "LucasCode"
 *
 * Copyright (C) 2005-2008 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace QuickLoad
{
    enum GameFileType
    {
        None,
        Screenshot,
        Replay,
        Aequitas,
        CompressedContent
    }
    static class Helpers
    {
        public static GameFileType getGameFileType(string path)
        {
            string ext = Path.GetExtension(path).ToLower();
            if (ext == ".dem")
                return GameFileType.Replay;
            else if (ext == ".bmp" || ext == ".jpg")
                return GameFileType.Screenshot;
            else if (ext == ".zip" && isAequitasFile(path))
                return GameFileType.Aequitas;
            else if (ext == ".zip")
                return GameFileType.CompressedContent;
            else
                return GameFileType.None;
        }
        public static string getFormattedKiloBytes(long Bytes)
        {
            string s = Math.Round((double)Bytes / 1000, 0).ToString();
            //for(int i=0;i<s.Length;i++)
            //{
            //    
            //
            int sl = s.Length;
            for (int i = sl; i > 0; i--)
            {
                if (sl-i > 0 && (sl-i) % 3 == 0)
                    s = s.Insert(i, ".");
            }
            return s;
        }
        public static bool isAequitasFile(string path)
        {
            DirectoryInfo d = new DirectoryInfo(System.IO.Path.GetDirectoryName(path));
            if (Path.GetExtension(path).ToLower() == ".zip"
                && System.IO.Path.GetDirectoryName(path).ToLower().EndsWith(Path.DirectorySeparatorChar + "archive")
                && File.Exists(d.Parent.FullName + Path.DirectorySeparatorChar + "aequitas.exe"))
                return true;
            else
                return false;
        }
    }
}
